<?php

namespace Biz\Resources\Site;

use Lumen\Http\Resources\Json\Resource;

/**
 * SiteOrderHotelReservationResource.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class SiteOrderHotelReservationResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        return [
            'uid'            => $this->uid,
            'hotel_name'     => $this->hotel_name,
            'room_type_name' => $this->room_type_name,
            'reservation_no' => $this->reservation_no,
            'room_price'     => money_format('%i', $this->room_price),
            'room_number'    => $this->room_number,
            'check_in_date'  => $this->check_in_date,
            'check_out_date' => $this->check_out_date,
            'remark'         => $this->remark,
            'created_at'     => $this->created_at->getTimestamp(),
            $this->mergeWhen($this->relationLoaded('order'), [
                'order' => $this->getSiteOrderResource(),
            ]),
        ];
    }

    /**
     * Get app resource.
     *
     * @return SitePayEaseResource|null
     */
    public function getSiteOrderResource()
    {
        if ($this->relationLoaded('order')) {
            return new SiteOrderResource($this->order);
        }

        return null;
    }
}
